var prefix = ctx+"/system/commonreportstatistics";

$(document).ready(function () {
    var id = getQueryString("id");
   // Get_Model_By_Query(id);

});

// 加载修改对象 
function Get_Model_By_Query(id) {
    var paramSearch = Get_Params_Search();
    if (id != null) {
        paramSearch.id = id;
    }
    console.log("id="+id);
    $.ajax({
        cache: true,
        type: "Get",
        url: prefix + "/Get_Model_By_Query",
        data: paramSearch,
        async: false,
        error: function (request) {
            parent.layer.alert("Connection error");
        },
        success: function (data) {
            $("#sid").val(data.sid);
            $("#sname").val(data.sname);
            $("#computerTsql").val(data.computerTsql);
            $("#sqlParams").val(data.sqlParams);
        }
    });
}

function fun_editModel() {
    var param = Get_Params();
    if (Vel_Param(param)) {
        $.ajax({
            cache: true,
            type: "POST",
            url: prefix + "/update",
            data: param,
            async: false,
            error: function (request) {
                parent.layer.alert("Connection error");
            },
            success: function (data) {
                if (data.code == 0) {
                    parent.layer.msg("操作成功");
                   // parent.fun_init();// 执行父页面的事件
                   // var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                   // parent.layer.close(index);

                } else {
                    parent.layer.alert(data.msg)
                }
            }
        });
    }
}

function fun_Close() {
    var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
    parent.layer.close(index);
}

function Get_Params_Search() {
    return {

    };
}

function Get_Params() {
    return {
        sid: $("#sid").val(),// 编号
        sname: $("#sname").val(),// 报表标题
        computerTsql: $("#computer_tsql").val(),// table-SQl语句
        sqlParams: $("#sql_params").val(),// 图标/表格
    };
}

function Vel_Param(param) {
    var msg = "";

    if (msg.length > 0) {
        parent.layer.msg(msg);
        return false;
    }

    else {
        return true;
    }
}

function ExecutClick() {
    div_report.style.width = $("#REPORT_DESCRIPTION").width() + 105 + 'px';
    var REPORT_SQL_ = document.all.computer_tsql.value.toUpperCase();

    $.ajax({
        type: "get",

        url: prefix + "/listReport",// '../../PublicInfoManage/COMMONREPORT/GetExecuteData',
        data: {
            sqlContent: REPORT_SQL_,
            SQL_PARAMS: $('#sql_params').val()
        },
        async: false,
        success: function (data) {

            var showtable = "<table class='hovertable'>";

            $.each(
                data,
                function (index, item) {

                    if (index == 0) {
                        showtable += "<tr>";
                        $.each(item, function (_key) {
                          //  console.log(_key);
                            showtable += "<th>" + _key
                                + "</th>"; // 拼接：表格标题

                        });
                        showtable += "</tr>";
                    }
                    showtable += "<tr onmouseover=\"this.style.backgroundColor='#ffff66';\" onmouseout=\"this.style.backgroundColor='#d4e3e5';\">";
                    $.each(item, function (_key) {

                        if (item[_key] == null) {
                            item[_key] = "-"
                        }
                        showtable += "<td>" + item[_key]
                            + "</td>"; // 拼接：表格内容
                    });
                    showtable += "</tr>";

                });
            showtable += "</table>";
            $("#div_report").html(showtable);
        }

    });

}
